import { defineStore } from "pinia";
import { ref } from "vue";

import { getLoginUserUsingGet } from "@/api/userController";

export const userLoginUserStore = defineStore("Loginuser", () => {
  const loginUser = ref({
    name: "",
  });
  const setLoginUser = (newLoginUser) => {
    loginUser.value = newLoginUser;
  };

  const fetchLoginUser = async () => {
    const res = await getLoginUserUsingGet();
    if (res.data.code == 0 && res.data.data) {
      loginUser.value = res.data.data;
    }
  };

  const deleteLoginUser = () => {
    loginUser.value = {};
  };
  return { loginUser, fetchLoginUser, deleteLoginUser, setLoginUser };
});
